package com.topfinance.cnaps2.web.sys;

import java.util.HashMap;

import com.topfinance.cnaps2.ebo.SysUserEbo;
import com.topfinance.cnaps2.service.ISysUserManager;
import com.topfinance.cnaps2.util.Constants;
import com.topfinance.frame.web.BaseSupport;

/**
 * <p>
 * Description:
 * </p>
 * 
 * @author
 * @version 1.50
 *          <p>
 *          Copyright: Copyright (c) 2004 2005
 *          </p>
 *          <p>
 *          Company:
 *          </p>
 */
public final class SysLoginAction extends BaseSupport{

	private ISysUserManager userManager = null;
	private String loginname;
	private String password;

	public void setSysUserManager(ISysUserManager userManager) {
		this.userManager = userManager;
	}

	public SysLoginAction() {
		super();
	}

	public String execute() {
		return login();
	}

	public String login() {
		try {
			System.out.println(loginname+"dddddddddddddd"+password);
			SysUserEbo user = userManager.checkLoginUser(loginname, password);
			log.debug("[Login User]" + user);
			sessionMap.put(Constants.SESSION_USER_EBO, user);
			rtnResultMap = new HashMap();
			rtnResultMap.put("success", Boolean.toString(user != null));
			String[] args = new String[1];
			args[0] = "";// you can add extra message here.
			//rtnResultMap.put("info", getText(DELETE_SUCCESS_KEY, args));
		} catch (Exception e) {
			handleException(e);
		}
		return SUCCESS;
	}	

	public String logout() {
		try {
			SysUserEbo user = (SysUserEbo)sessionMap.get(Constants.SESSION_USER_EBO);
			log.debug("[Logout User]" + user);
			sessionMap.remove(Constants.SESSION_USER_EBO);
			rtnResultMap = new HashMap();
			rtnResultMap.put("success", Boolean.toString(user != null));
			String[] args = new String[1];
		} catch (Exception e) {
			handleException(e);
		}
		return SUCCESS;
	}
	
	public String unlogin() {
		try {
			rtnResultMap = new HashMap();
			SysUserEbo user = (SysUserEbo)sessionMap.get(Constants.SESSION_USER_EBO);
			log.debug("[UnLogin User]" + user);
			rtnResultMap.put("unlogin", Boolean.valueOf(user==null));
		} catch (Exception e) {
			handleException(e);
		}
		return SUCCESS;
	}

	public String getLoginname() {
		return loginname;
	}

	public void setLoginname(String loginname) {
		this.loginname = loginname;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}	
	
}
